﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cn.Edwon.Web.Support;

namespace Cn.Cellula.Website.Ws {
    public partial class _Export : PageSupport {
        protected void Page_Load(object sender, EventArgs e) {
            String paramName = Request.QueryString["pn"];
            String fileName = Request.QueryString["fn"];
            String fileType = Request.QueryString["ft"];
            String content = Request.Form[paramName];
            try {
                Export(fileType, fileName, content);
            } catch (Exception ex) {
                log.Error("_Export:"+ex.Message);
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "","alert('"+ex.Message.Replace("'","")+"');", true);
            }
        }   

        private void Export(String rFileType,String rFileName,String rContent) {
            Response.Clear();
            Response.Buffer = true;
            Response.ContentEncoding = System.Text.Encoding.Default;
            Response.ContentType = "application/" + rFileType;
            Response.AppendHeader("content-disposition", "attachment;filename="+rFileName);
            Response.Write(rContent);
            Response.End();
        }

    }
}